Account : Account information

更新时间:
2024-05-15
下载文档

Account : Account information

This module is EdgerOS account information acquisition module. Apps can use this module to acquire user information of specified account. This module is available in EdgerOS 1.6.0 and later.

This module is the asynchronous mode of the account module. User can use the following code to import the account module.

var account = require('async/account');

Support

The following shows account module APIs available for each permissions.

 User ModePrivilege Mode
account.list
account.groups
account.remarks
account.info
account.mname
account.update
account.gpdate

Account Object

async account.list([simple])

  • simple {Boolean} Whether only need acoid information. default: false.
  • Returns: {Array} Account list.

Get the account list of the current machine.

Example

var list = await account.list();
list.forEach(function(u) {
  // u.acoid, u.alias, u.group, u.extra
});

var list = await account.list(true);
list.forEach(function(acoid) {
  // acoid
});

Get account profile: In EdgerOS 2.0.0 and later versions, the account.list API will return account information contains extra attribute. For privilege app, extra contains full information, for non privilege app, extra only contains profile attribute. The developer can use the following code to display user profile in web page:

var profile = ......; // get profile from REST api
var { protocol, hostname } = window.location;
var addr = `${protocol}//${hostname}${profile}`; // build profile URL

var img = new Image();
img.src = addr;

This profile is cached by the current EdgerOS machine, which can be obtained offline, and EdgerOS will update the profile every time when user browse the account details.

async account.groups()

  • Returns: {Array} Group list.

Get the group list of the current machine. App developers can use the account.list and account.groups functions to implement more refined permission management within the app.

Example

var list = await account.groups();
console.log('groups:', list);

async account.remarks(acoid)

  • acoid {String} Account id.
  • Returns: {Array} Remarks list.

Get the specified user's remarks setting of other users in current machine. This function is available on EdgerOS 1.10.2 and above.

Each object in the returned array contains the following members:

  • acoid {String} Account id.
  • remark {String} Account remark.

async account.info(acoid)

  • acoid {String} Account id.
  • Returns: {Object} Account information.

Get account information by acoid. The account information object contains the following members:

  • acoid {String} Account id.
  • group {String} Account group name.
  • alias {String} Account alias name.
  • extra {Object} Account extra information.
groupDescription
'admin'Current device administrator group.
'user'Current device user group.
'guest'Guest group.

Example

async function isAdmin(acoid) {
  try {
    var info = await account.info(acoid);
  } catch (error) {
    console.error('isAdmin() call error:', error);
    return false;
  }
  return info.group === 'admin';
}

async account.mname()

  • Returns: {String} Current machine name.

Get current machine name.

Example

account.mname().then(mname => {
  console.log('Current mname:', mname);
}, console.error);

account.update(callback)

  • callback {Function} Callback function.
    • event {String} Account event.
    • acoid {String} Account id.

Registered account status change callback function. The following events may occur:

eventDescription
'add'Add a new account to the current device.
'delete'Remove an account from the current device.
'update'The specified account information changed.

Example

account.update(function(event, acoid) {
  // Perform different actions according to different events.
});

account.gpdate(callback)

  • callback {Function} Callback function.
    • event {String} Group event.
    • group {String} Group name.
    • previous {String} Group previous name. Only valid on 'update' event.

Registered group status change callback function. The following events may occur:

eventDescription
'add'Add a new group to the current device.
'delete'Remove an group from the current device.
'update'The specified group changed name.

Example

account.gpdate(function(event, group, previous) {
  // Perform different actions according to different events.
});
文档内容是否对您有所帮助?
有帮助
没帮助